﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FOModels.Ads;
namespace DataAccess.Ads
{
    public class AdsDAL
    {
        private SQLDataAccess db;
        public AdsDAL()
        {
            db = new SQLDataAccess();
        }
        public DataTable getAdsPage()
        {
            return db.exeSelect("Select * from AdsPage");
        }
        public DataTable getAdsPosition()
        {
            return db.exeSelect("Select * from AdsPosition");
        }
        public DataTable getAdsByPageID(int AdsPageID,int AdsPositionID,int langid)
        {
            return db.exeSelect("Select TOP 1 * from Ads a join AdsLang ad on a.AdsID = ad.AdsID where AdsPageID = " + AdsPageID + " and AdsPositionID = " + AdsPositionID + " and AdsLangID = " + langid + "");
        }
        public DataTable getAdsByIDToManager(int AdsID,int langid)
        {
            return db.exeSelect("Select * from Ads a join AdsLang ad on a.AdsID = ad.AdsID where a.AdsID = " + AdsID + " and ad.AdsLangID = "+langid+"");
        }
        public DataTable getAdsToManager(int langid)
        {
            return db.exeSelect("Select * from Ads a join AdsLang ad on a.AdsID = ad.AdsID join [Language] la on ad.AdsLangID = la.ID join AdsPage adp on a.AdsPageID = adp.AdsPageID join AdsPosition ads on a.AdsPositionID = ads.AdsPositionID where ad.AdsLangID = " + langid + "");
        }
        public DataTable getTop1Ads()
        {
            return db.exeSelect("Select TOP 1 * from Ads order by AdsID desc");
        }
        public int DeleteAds(int AdsID)
        {
            return db.exeUpdate("Delete from Ads where AdsID = " + AdsID + "");
        }
        public int DeleteAdsLang(int AdsID)
        {
            return db.exeUpdate("Delete from AdsLang where AdsID = " + AdsID + "");
        }
        public int UpdateAdsLang(AdsModels ads, int langid)
        {
            return db.exeUpdate("update AdsLang set AdsName = N'" + ads.AdsName + "',AdsImg ='" + ads.AdsImg + "',AdsImgInfo='" + ads.AdsImgInfo + "' where AdsID =" + ads.AdsID + " and AdsLangID =" + langid + "");
        }
        public int UpdateAds(AdsModels ads)
        {
            return db.exeUpdate("update Ads set AdsPageID = " + ads.AdsPageID + ",AdsPositionID ='" + ads.AdsPositionID + "',AdsActive='" + ads.AdsActive + "',AdsUrlImgInfo='" + ads.AdsUrlImgInfo + "'where AdsID = " + ads.AdsID + "");
        }

        public int InsertAdsLang(AdsModels ads, int langid)
        {
            return db.exeUpdate("insert into AdsLang values (" + ads.AdsID + "," + langid + ",N'" + ads.AdsName + "',N'" + ads.AdsImg + "',N'" + ads.AdsImgInfo + "')");
        }
        public int InsertAds(AdsModels ads)
        {
            return db.exeUpdate("insert into Ads values (" + ads.AdsPageID + "," + ads.AdsPositionID + ",'" + ads.AdsActive + "',N'" + ads.AdsUrlImgInfo + "')");
        }
    }
}
